<?php

namespace app\index\model;

use think\admin\Model;

/**
 * @name:计划
 * @author:Sam
 * @date:2024-09-01
*/
class Plan extends Model
{
    protected $table = "dc_plan";

    public function user(){
        return $this->belongsTo(Users::class,'uid');
    }

    public function crane(){
        return $this->belongsTo(Crane::class,'crane_id');
    }


    public function getStatusTextAttr($value,$data){
        $status = [0=>'未完成',1=>'已完成',2=>'未完成'];
        return $status[$data['status']] ?? '未知状态';
    }
    // public function getStartTimeAttr($value){
    //     return date('Y-m-d H:i',strtotime($value));
    // }

    public function getCompleteTimeTimeAttr($value){
        return $value ? date('Y-m-d H:i',strtotime($value)) : '';
    }
    public function getStartTimeAttr($value){
        return $value ? date('Y-m-d H:i',strtotime($value)) : '';
    }

    public function getEndTimeAttr($value){
        return $value ? date('Y-m-d H:i',strtotime($value)) : '';
    }



    public function segment(){
        //分段类型
        return $this->belongsTo(SegmentType::class,'segment_type_id');
    }

    public function stage(){


        return $this->belongsTo(ProductionStage::class,'production_stage_id');
    }


    public function  getTrueCircleAttr($value,$data){
        return $data['complete_time'] ? round((strtotime($data['complete_time']) - strtotime($data['start_time'])) / 60) : '---';
    }
}